package com.gxa.p2p.controller;

import com.alibaba.excel.EasyExcel;
import com.gxa.p2p.common.JsonResult;
import com.gxa.p2p.pojo.*;
import com.gxa.p2p.service.PlatFormService;
import com.gxa.p2p.util.StringUtil;
import io.swagger.annotations.*;
import org.apache.poi.hssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

/**
 * @Author xhy
 * @Date 2021/10/26 10:56
 */
@CrossOrigin
@RestController
@RequestMapping("/moneyManage")
@WebAppConfiguration
@Component
@Api(value = "平台，用户资金管理及日志")
public class MoneyManageController {

    @Autowired
    private PlatFormService platFormService = null;

    @PostMapping("/userMoney")
    @ApiOperation("查找用户资金")
    @ApiImplicitParams({
            @ApiImplicitParam(name="name",value = "用户的姓名",required = false),
            @ApiImplicitParam(name="phone",value = "用户的电话",required = false),
            @ApiImplicitParam(name="userType",value = "用户类型",required = false),
            @ApiImplicitParam(name="page",value = "分页中的页码",required = true),
            @ApiImplicitParam(name="size",value = "分页中的每页记录数,默认为10",required = true),
    })
    public Map findUserMoney(String name,
                             String phone,
                             String userType,
                             Integer page,
                             Integer size){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        List<UserMoneyVo> userRecord = platFormService.findInvestAndBorrowUser(name, phone, userType, page, size);
        jsonResult.setData(userRecord);
        List<UserMoneyVo> investAndBorrowUser = platFormService.findInvestAndBorrowUser(name, phone, userType);
        jsonResult.put("count",investAndBorrowUser.size());
        return jsonResult.getDataMap();
    }

    @PostMapping("/moneyLog")
    @ApiOperation("查询资金日志")
    @ApiImplicitParams({
            @ApiImplicitParam(name="name",value = "用户的姓名",required = false),
            @ApiImplicitParam(name="phone",value = "用户的电话",required = false),
            @ApiImplicitParam(name="type",value = "资金类型",required = false),
            @ApiImplicitParam(name="page",value = "分页中的页码",required = true),
            @ApiImplicitParam(name="size",value = "分页中的每页记录数,默认为10",required = true),
    })
    public Map checkLog(String name,
                        String phone,
                        String type,
                        Integer page,
                        Integer size){
        List<UserRecordVo> platfromlog = platFormService.findPlatfromlog(name, phone, type, page, size);
        List<UserRecordVo> platfromlog1 = platFormService.findPlatfromlog(name, phone, type);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(platfromlog);
        jsonResult.put("count",platfromlog1.size());
        return jsonResult.getDataMap();
    }

    @PostMapping("/platMoney")
    @ApiOperation("查看平台资金")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "流水单号",required = false),
            @ApiImplicitParam(name="type",value = "资金类型",required = false),
            @ApiImplicitParam(name="outOrIn",value = "出入账",required = false),
            @ApiImplicitParam(name="page",value = "分页中的页码",required = true),
            @ApiImplicitParam(name="size",value = "分页中的每页记录数,默认为10",required = true)
    })
    public Map checkPlatformMoney(Long id,
                                  String type,
                                  String outOrIn,
                                  Integer page,
                                  Integer size){
        List<Platform> allPlatForm = platFormService.findAllPlatForm(id, type, outOrIn, page, size);
        List<Platform> allPlatForm1 = platFormService.findAllPlatForm(id, type, outOrIn);
        Double platformBalance = platFormService.findPlatformBalance();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.put("platformAllMoney",platformBalance);
        jsonResult.setData(allPlatForm);
        jsonResult.put("count",allPlatForm1.size());
        return jsonResult.getDataMap();
    }

    @PostMapping("/platRecharge")
    @ApiOperation("平台充值")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "用户手机",required = true),
            @ApiImplicitParam(name = "name",value = "用户姓名",required = true),
            @ApiImplicitParam(name = "source",value = "用户来源",required = true),
            @ApiImplicitParam(name = "application",value = "应用来源",required = true),
            @ApiImplicitParam(name = "recharge",value = "充值金额",required = true),
            @ApiImplicitParam(name = "arrivalAmount",value = "到账金额",required = true),
            @ApiImplicitParam(name = "serviceCharge",value = "提现手续费",required = true),
            @ApiImplicitParam(name = "type",value = "充值方式",required = true)
    })
    public Map platRecharge(String phone,
                            String name,
                            String source,
                            String application,
                            Double recharge,
                            Double arrivalAmount,
                            Double serviceCharge,
                            String type){
        Rechargerecord rechargerecord = new Rechargerecord();
        rechargerecord.setInvestPhone(phone);
        rechargerecord.setInverstName(name);
        rechargerecord.setInvestOrigin(source);
        rechargerecord.setApplicationOrigin(application);
        rechargerecord.setRecharageMoney(recharge);
        rechargerecord.setRecievedMoney(arrivalAmount);
        rechargerecord.setServiceMoney(serviceCharge);
        rechargerecord.setRechargeType(type);
        rechargerecord.setRemarks(null);
        rechargerecord.setRecievedTime(null);
        rechargerecord.setMoneyType("充值出账");

        rechargerecord.setSerialNumber(null);
        rechargerecord.setOrderTime(new Timestamp(System.currentTimeMillis()));
        rechargerecord.setState(true);
        platFormService.platRecharge(rechargerecord);

        Platform platform = new Platform();
        platform.setId(rechargerecord.getId());
        platform.setType("平台充值");
        platform.setOutOrIn("入账");
        platform.setHandleMoney(rechargerecord.getRecharageMoney());
        platform.setPoundage(rechargerecord.getServiceMoney());
        platform.setBeforeHandle(platFormService.findPlatformBalance());
        platform.setAfterHandle(platFormService.findPlatformBalance()+rechargerecord.getRecievedMoney()+rechargerecord.getServiceMoney());
        platform.setState(true);
        platform.setRemarks("");
        platform.setHandleTime(rechargerecord.getOrderTime());
        platFormService.insertPlatformRecharge(platform);

        platFormService.rechargeInvestUserMoney(rechargerecord.getInvestPhone(),rechargerecord.getRecharageMoney());
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }

    @PostMapping("/platWithdrawal")
    @ApiOperation("平台提现")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "用户手机",required = true),
            @ApiImplicitParam(name = "name",value = "姓名",required = true),
            @ApiImplicitParam(name = "userType",value = "用户类型",required = true),
            @ApiImplicitParam(name = "withdrawDeposit",value = "提现金额",required = true),
            @ApiImplicitParam(name = "serviceCharge",value = "提现手续费",required = true),
            @ApiImplicitParam(name = "arrivalAmount",value = "到账金额",required = true),
            @ApiImplicitParam(name = "bankName",value = "银行名称",required = true),
            @ApiImplicitParam(name = "bankId",value = "银行卡号",required = true)
    })
    public Map platWithdrawal(
            String phone,
            String name,
            String userType,
            Double withdrawDeposit,
            Double serviceCharge,
            Double arrivalAmount,
            String bankName,
            String bankId){
        Outrecord outrecord = new Outrecord();
        outrecord.setUserName(name);
        outrecord.setUserPhone(phone);
        outrecord.setUserType(userType);
        outrecord.setOutMoney(withdrawDeposit);
        outrecord.setOutCost(serviceCharge);
        outrecord.setGetMoney(arrivalAmount);
        outrecord.setBankName(bankName);
        outrecord.setBankId(bankId);
        outrecord.setBankSerial("");
        outrecord.setSubmitTime(new Timestamp(System.currentTimeMillis()));
        outrecord.setState("待审核");
        platFormService.platWithdrawal(outrecord);
        platFormService.outInvestUserMoney(outrecord.getUserPhone(),outrecord.getGetMoney());

        Platform platform = new Platform();
        platform.setId(outrecord.getId());
        platform.setType("平台提现");
        platform.setOutOrIn("出账");
        platform.setHandleMoney(outrecord.getOutMoney());
        platform.setPoundage(outrecord.getOutCost());
        platform.setBeforeHandle(platFormService.findPlatformBalance());
        platform.setAfterHandle(platFormService.findPlatformBalance()-outrecord.getGetMoney()+outrecord.getOutCost());
        platform.setState(true);
        platform.setRemarks("");
        platform.setHandleTime(outrecord.getSubmitTime());
        platform.setState(true);
        platFormService.insertPlatformRecharge(platform);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }


    /**
     * 徐海鱼
     * */
    @GetMapping("/export/platMoney")
    @ApiOperation("导出平台资金")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "流水单号",required = false),
            @ApiImplicitParam(name="type",value = "资金类型",required = false),
            @ApiImplicitParam(name="outOrIn",value = "出入账",required = false)
    })
    public void exportPlatformMoney(HttpServletResponse response,
                                    Long id,
                                    String type,
                                    String outOrIn) throws IOException {
        //要导出的数据
        List<Platform> allPlatForm = platFormService.findAllPlatForm(id, type, outOrIn);
        // 工作簿对象
        HSSFWorkbook workbook = new HSSFWorkbook();
        // 创建工作表
        HSSFSheet sheet = workbook.createSheet("平台资金表");
        String fileName = "平台资金表" + ".xls";
        // 将文件名中的中文部分被URL编码后的内容进行解析, 最终还是显示为中文状态
        fileName = URLEncoder.encode(fileName, "utf-8").replaceAll("\\+", "%20");
        // headers表示excel表中第一行的表头 在excel表中添加表头
        String[] headers = {"流水号", "类型", "出入账", "操作金额", "手续费", "操作前余额", "操作后余额", "状态", "备注", "操作时间"};
        // 创建一个行对象, 作为表头
        HSSFRow row = sheet.createRow(0);
        for (int i = 0; i < headers.length; i++) {
            HSSFCell cell = row.createCell(i);   // 在行中添加单元格
            HSSFRichTextString text = new HSSFRichTextString(headers[i]);
            cell.setCellValue(text);   // 把字段名添加到表头行上
        }
        //准备将时间格式处理为标准日期格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 添加数据行:
        int rowNum = 1;
        for (Platform item : allPlatForm) {
            HSSFRow dataRow = sheet.createRow(rowNum);
            if (item.getId() == null) {
                dataRow.createCell(0).setCellValue("");
            } else {
                dataRow.createCell(0).setCellValue(item.getId());
            }

            if (item.getType() == null) {
                dataRow.createCell(1).setCellValue("");
            } else {
                dataRow.createCell(1).setCellValue(item.getType());
            }

            if (item.getOutOrIn() == null) {
                dataRow.createCell(2).setCellValue("");
            } else {
                dataRow.createCell(2).setCellValue(item.getOutOrIn());
            }

            if (item.getHandleMoney() == null) {
                dataRow.createCell(3).setCellValue("");
            } else {
                dataRow.createCell(3).setCellValue(item.getHandleMoney());
            }

            if (item.getPoundage() == null) {
                dataRow.createCell(4).setCellValue("");
            } else {
                dataRow.createCell(4).setCellValue(item.getPoundage());
            }

            if (item.getBeforeHandle() == null) {
                dataRow.createCell(5).setCellValue("");
            } else {
                dataRow.createCell(5).setCellValue(item.getBeforeHandle());
            }

            if (item.getAfterHandle() == null) {
                dataRow.createCell(6).setCellValue("");
            } else {
                dataRow.createCell(6).setCellValue(item.getAfterHandle());
            }

            if (item.getState() == null) {
                dataRow.createCell(7).setCellValue("");
            } else {
                dataRow.createCell(7).setCellValue(item.getState());
            }

            if (item.getRemarks() == null) {
                dataRow.createCell(8).setCellValue("");
            } else {
                dataRow.createCell(8).setCellValue(item.getRemarks());
            }

            if (item.getHandleTime() == null) {
                dataRow.createCell(9).setCellValue("");
            } else {
                dataRow.createCell(9).setCellValue(item.getHandleTime());
            }
            rowNum++;
        }
        //返回给前端下载
        response.setContentType("application/octet-stream");
        //附件格式打卡，不是打开页面
        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
        response.flushBuffer();
        workbook.write(response.getOutputStream());
    }

    /**
     * 徐海鱼
     * */
    @GetMapping("/export/moneyLog")
    @ApiOperation("导出资金日志")
    @ApiImplicitParams({
            @ApiImplicitParam(name="name",value = "用户的姓名",required = false),
            @ApiImplicitParam(name="phone",value = "用户的电话",required = false),
            @ApiImplicitParam(name="type",value = "资金类型",required = false),
    })
    public void exportMoneyLog(String name,
                               String phone,
                               String type,
                               HttpServletResponse response) throws Exception {
        //要导出的数据
        List<UserRecordVo> platfromlog = platFormService.findPlatfromlog(name, phone, type);
        // 工作簿对象
        HSSFWorkbook workbook = new HSSFWorkbook();
        // 创建工作表
        HSSFSheet sheet = workbook.createSheet("资金日志表");
        String fileName = "资金日志表" + ".xls";
        // 将文件名中的中文部分被URL编码后的内容进行解析, 最终还是显示为中文状态
        fileName = URLEncoder.encode(fileName, "utf-8").replaceAll("\\+", "%20");
        // headers表示excel表中第一行的表头 在excel表中添加表头
        String[] headers = {"姓名", "用户手机", "类型", "操作金额", "操作前可用金额", "擦操作后可用金额", "操作前冻结金额", "操作后冻结金额", "备注", "操作时间"};
        // 创建一个行对象, 作为表头
        HSSFRow row = sheet.createRow(0);
        for (int i = 0; i < headers.length; i++) {
            HSSFCell cell = row.createCell(i);   // 在行中添加单元格
            HSSFRichTextString text = new HSSFRichTextString(headers[i]);
            cell.setCellValue(text);   // 把字段名添加到表头行上
        }
        System.out.println("1");
        // 添加数据行:
        int rowNum = 1;
        for (UserRecordVo item : platfromlog) {
            HSSFRow dataRow = sheet.createRow(rowNum);
            if (item.getName() == null) {
                dataRow.createCell(0).setCellValue("");
            } else {
                dataRow.createCell(0).setCellValue(item.getName());
            }

            if (item.getPhone() == null) {
                dataRow.createCell(1).setCellValue("");
            } else {
                dataRow.createCell(1).setCellValue(item.getPhone());
            }

            if (item.getMoneyType() == null) {
                dataRow.createCell(2).setCellValue("");
            } else {
                dataRow.createCell(2).setCellValue(item.getMoneyType());
            }

            if (item.getOperatMoney() == null) {
                dataRow.createCell(3).setCellValue("");
            } else {
                dataRow.createCell(3).setCellValue(item.getOperatMoney());
            }

            if (item.getBeforeUsedMoney() == null) {
                dataRow.createCell(4).setCellValue("");
            } else {
                dataRow.createCell(4).setCellValue(item.getBeforeUsedMoney());
            }

            if (item.getAfterUsedMoney() == null) {
                dataRow.createCell(5).setCellValue("");
            } else {
                dataRow.createCell(5).setCellValue(item.getAfterUsedMoney());
            }

            if (item.getBeforeFreezeMoney() == null) {
                dataRow.createCell(6).setCellValue("");
            } else {
                dataRow.createCell(6).setCellValue(item.getBeforeFreezeMoney());
            }

            if (item.getAfterFreezeMoney() == null) {
                dataRow.createCell(7).setCellValue("");
            } else {
                dataRow.createCell(7).setCellValue(item.getAfterFreezeMoney());
            }

            if (item.getRemarks() == null) {
                dataRow.createCell(8).setCellValue("");
            } else {
                dataRow.createCell(8).setCellValue(item.getRemarks());
            }

            if (item.getOperatTime() == null) {
                dataRow.createCell(9).setCellValue("");
            } else {
                dataRow.createCell(9).setCellValue(item.getOperatTime());
            }
            rowNum++;
            System.out.println(item);
        }
        System.out.println("2");
        //返回给前端下载
        response.setContentType("application/octet-stream");
        //附件格式打卡，不是打开页面
        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
        response.flushBuffer();
        workbook.write(response.getOutputStream());
    }

    @GetMapping("/export/userMoney")
    @ApiOperation("导出用户资金")
    @ApiImplicitParams({
            @ApiImplicitParam(name="name",value = "用户的姓名",required = false),
            @ApiImplicitParam(name="phone",value = "用户的电话",required = false),
            @ApiImplicitParam(name="userType",value = "用户类型",required = false),
    })
    public void exportUserMoney(String name,
                                String phone,
                                String userType,
                                HttpServletResponse response) throws Exception{
        //要导出的数据
        List<UserMoneyVo> investAndBorrowUser = platFormService.findInvestAndBorrowUser(name, phone, userType);
        // 工作簿对象
        HSSFWorkbook workbook = new HSSFWorkbook();
        // 创建工作表
        HSSFSheet sheet = workbook.createSheet("用户资金表");
        String fileName = "用户资金表" + ".xls";
        // 将文件名中的中文部分被URL编码后的内容进行解析, 最终还是显示为中文状态
        fileName = URLEncoder.encode(fileName, "utf-8").replaceAll("\\+", "%20");
        // headers表示excel表中第一行的表头 在excel表中添加表头
        String[] headers = {"用户ID", "姓名", "用户手机", "总资产", "可用余额", "冻结金额", "待收金额", "累计投资", "累计投资收益", "累计借款", "累计还款","借还款差额"};
        // 创建一个行对象, 作为表头
        HSSFRow row = sheet.createRow(0);
        for (int i = 0; i < headers.length; i++) {
            HSSFCell cell = row.createCell(i);   // 在行中添加单元格
            HSSFRichTextString text = new HSSFRichTextString(headers[i]);
            cell.setCellValue(text);   // 把字段名添加到表头行上
        }
        // 添加数据行:
        int rowNum = 1;
        for (UserMoneyVo item : investAndBorrowUser) {
            HSSFRow dataRow = sheet.createRow(rowNum);
            if (item.getId() == null) {
                dataRow.createCell(0).setCellValue("");
            } else {
                dataRow.createCell(0).setCellValue(item.getId());
            }

            if (item.getName() == null) {
                dataRow.createCell(1).setCellValue("");
            } else {
                dataRow.createCell(1).setCellValue(item.getName());
            }

            if (item.getPhone() == null) {
                dataRow.createCell(2).setCellValue("");
            } else {
                dataRow.createCell(2).setCellValue(item.getPhone());
            }

            if (item.getAllMoney() == null) {
                dataRow.createCell(3).setCellValue("");
            } else {
                dataRow.createCell(3).setCellValue(item.getAllMoney());
            }

            if (item.getUsedMoney() == null) {
                dataRow.createCell(4).setCellValue("");
            } else {
                dataRow.createCell(4).setCellValue(item.getUsedMoney());
            }

            if (item.getFreezeMoney() == null) {
                dataRow.createCell(5).setCellValue("");
            } else {
                dataRow.createCell(5).setCellValue(item.getFreezeMoney());
            }

            if (item.getNoRecivedMoney() == null) {
                dataRow.createCell(6).setCellValue("");
            } else {
                dataRow.createCell(6).setCellValue(item.getNoRecivedMoney());
            }

            if (item.getSumInvestMoney() == null) {
                dataRow.createCell(7).setCellValue("");
            } else {
                dataRow.createCell(7).setCellValue(item.getSumInvestMoney());
            }

            if (item.getSumInvestIncomeMoney() == null) {
                dataRow.createCell(8).setCellValue("");
            } else {
                dataRow.createCell(8).setCellValue(item.getSumInvestIncomeMoney());
            }

            if (item.getSumBorrowMoney() == null) {
                dataRow.createCell(9).setCellValue("");
            } else {
                dataRow.createCell(9).setCellValue(item.getSumBorrowMoney());
            }

            if (item.getSumRepayMoney() == null) {
                dataRow.createCell(10).setCellValue("");
            } else {
                dataRow.createCell(10).setCellValue(item.getSumRepayMoney());
            }
            if (item.getBanlanceMoney() == null) {
                dataRow.createCell(11).setCellValue("");
            } else {
                dataRow.createCell(11).setCellValue(item.getBanlanceMoney());
            }
            rowNum++;
        }
        //返回给前端下载
        response.setContentType("application/octet-stream");
        //附件格式打卡，不是打开页面
        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
        response.flushBuffer();
        workbook.write(response.getOutputStream());
    }

    @GetMapping("/export/findWithdrawlogByPage")
    @ApiOperation("导出提现记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "提现单号",required = false),
            @ApiImplicitParam(name = "userPhone",value = "用户电话号",required = false),

            @ApiImplicitParam(name = "userName",value = "用户真实姓名",required = false),
            @ApiImplicitParam(name = "from",value = "开始时间",required = false),
            @ApiImplicitParam(name = "to",value = "截至时间",required = false),
            @ApiImplicitParam(name = "bankId",value = "银行账号",required = false),
            @ApiImplicitParam(name = "bankName",value = "银行名称",required = false),
            @ApiImplicitParam(name = "page",value = "提现状态",required = false)
    })
    public void exportWithdrawlogByPage(Long id,
                                        String userPhone,
                                        String userName,
                                        String bankId,
                                        String bankName,
                                        String from,
                                        String to,
                                        HttpServletResponse response) throws IOException {
        //要导出的数据
        List<Outrecord> withdrawlogByPage = platFormService.exportWithdrawlogByPage(id, userPhone, userName, bankId, bankName, from, to);
        // 工作簿对象
        HSSFWorkbook workbook = new HSSFWorkbook();
        // 创建工作表
        HSSFSheet sheet = workbook.createSheet("提现审核记录表");
        String fileName = "提现审核记录表" + ".xls";
        // 将文件名中的中文部分被URL编码后的内容进行解析, 最终还是显示为中文状态
        fileName = URLEncoder.encode(fileName, "utf-8").replaceAll("\\+", "%20");
        // headers表示excel表中第一行的表头 在excel表中添加表头
        String[] headers = {"提现单号", "用户手机", "真实姓名", "用户类型", "提现金额", "提现手续费", "预计到账金额", "银行账号", "银行名称", "提交时间", "状态"};
        // 创建一个行对象, 作为表头
        HSSFRow row = sheet.createRow(0);
        for (int i = 0; i < headers.length; i++) {
            HSSFCell cell = row.createCell(i);   // 在行中添加单元格
            HSSFRichTextString text = new HSSFRichTextString(headers[i]);
            cell.setCellValue(text);   // 把字段名添加到表头行上
        }
        //准备将时间格式处理为标准日期格式
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 添加数据行:
        int rowNum = 1;
        for (Outrecord item : withdrawlogByPage) {
            HSSFRow dataRow = sheet.createRow(rowNum);
            if (item.getId() == null) {
                dataRow.createCell(0).setCellValue("");
            } else {
                dataRow.createCell(0).setCellValue(item.getId());
            }

            if (item.getUserPhone() == null) {
                dataRow.createCell(1).setCellValue("");
            } else {
                dataRow.createCell(1).setCellValue(item.getUserPhone());
            }

            if (item.getUserName() == null) {
                dataRow.createCell(2).setCellValue("");
            } else {
                dataRow.createCell(2).setCellValue(item.getUserName());
            }

            if (item.getUserName() == null) {
                dataRow.createCell(3).setCellValue("");
            } else {
                dataRow.createCell(3).setCellValue(item.getUserName());
            }

            if (item.getUserType() == null) {
                dataRow.createCell(4).setCellValue("");
            } else {
                dataRow.createCell(4).setCellValue(item.getUserType());
            }
            if (item.getOutMoney() == null) {
                dataRow.createCell(5).setCellValue("");
            } else {
                dataRow.createCell(5).setCellValue(item.getOutMoney());
            }
            if (item.getOutCost() == null) {
                dataRow.createCell(6).setCellValue("");
            } else {
                dataRow.createCell(6).setCellValue(item.getOutCost());
            }
            if (item.getGetMoney() == null) {
                dataRow.createCell(7).setCellValue("");
            } else {
                dataRow.createCell(7).setCellValue(item.getGetMoney());
            }
            if (item.getBankId() == null) {
                dataRow.createCell(8).setCellValue("");
            } else {
                dataRow.createCell(8).setCellValue(item.getBankId());
            }
            if (item.getBankName() == null) {
                dataRow.createCell(9).setCellValue("");
            } else {
                dataRow.createCell(9).setCellValue(item.getBankName());
            }
            if (item.getSubmitTime() == null) {
                dataRow.createCell(10).setCellValue("");
            } else {
                dataRow.createCell(10).setCellValue(item.getSubmitTime());
            }
            if (item.getState() == null) {
                dataRow.createCell(11).setCellValue("");
            } else {
                dataRow.createCell(11).setCellValue(item.getState());
            }

            rowNum++;
        }
        //返回给前端下载
        response.setContentType("application/octet-stream");
        //附件格式打卡，不是打开页面
        response.setHeader("Content-disposition", "attachment;filename=" + fileName);
        response.flushBuffer();
        workbook.write(response.getOutputStream());
    }

    @PostMapping("/updateOutRecordState")
    @ApiOperation("修改提现状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "提现单号",required = true),
            @ApiImplicitParam(name = "state",value = "提现状态",required = true),
            @ApiImplicitParam(name = "remarks",value = "审核备注",required = false)})
    public Map updateOutRecordState(Long id,
                                    String state,
                                    String remarks){
        platFormService.updateAuditState(id, state,remarks);
        Map map = platFormService.selectOutrecordUser(id);
        List<Outrecord> outrecords = platFormService.selectRecentOutrecord(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(map);
        jsonResult.put("recentRecord",outrecords);
        jsonResult.put("count",outrecords.size());
        return jsonResult.getDataMap();
    }

    @PostMapping("/updateOutRecordStateById")
    @ApiOperation("根据Id查找记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "提现单号",required = true)})
    public Map updateOutRecordStateById(Long id){
        Map map = platFormService.selectOutrecordUser(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(map);
        List<Outrecord> outrecords = platFormService.selectRecentOutrecord(id);
        jsonResult.put("recentRecord",outrecords);
        return jsonResult.getDataMap();
    }

    @PostMapping("/findWithdrawlogByPage")
    @ApiOperation("查找提现记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "提现单号",required = false),
            @ApiImplicitParam(name = "userPhone",value = "用户电话号",required = false),

            @ApiImplicitParam(name = "userName",value = "用户真实姓名",required = false),
            @ApiImplicitParam(name = "from",value = "开始时间",required = false),
            @ApiImplicitParam(name = "to",value = "截至时间",required = false),
            @ApiImplicitParam(name = "bankId",value = "银行账号",required = false),
            @ApiImplicitParam(name = "bankName",value = "银行名称",required = false),
            @ApiImplicitParam(name = "page",value = "提现页码",required = true),
            @ApiImplicitParam(name = "size",value = "提现记录页大小",required = true)
    })
    public Map exportWithdrawlogByPage(Long id,
                                       String userPhone,
                                       String userName,
                                       String bankId,
                                       String bankName,
                                       String from,
                                       String to,
                                       @RequestParam("page") Integer page,
                                       @RequestParam("size") Integer size
    ) throws IOException {
        List<Outrecord> withdrawlogByPage = platFormService.findWithdrawlog(id, userPhone, userName, bankId, bankName, from, to, page, size);
        List<Outrecord> outrecords = platFormService.exportWithdrawlogByPage(id, userPhone, userName, bankId, bankName, from, to);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(withdrawlogByPage);
        jsonResult.put("count",outrecords.size());
        return jsonResult.getDataMap();
    }
}
